/*
 * MotelPlusApp.java
 */

package motelplus;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import rad.Java.Common.DB.Database;
import rad.Java.Common.Forms.frmLogin;

/**
 * The main class of the application.
 */
public class MotelPlusApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        show(new MotelPlusView(this));
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of MotelPlusApp
     */
    public static MotelPlusApp getApplication() {
        return Application.getInstance(MotelPlusApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        Database.settings.setDatabaseProtocol(Database.SQLITE);
        Database.settings.setDatabaseName("database/MotelPlus.sqlite");

        if(!Database.connect())
        {
            JOptionPane.showMessageDialog(null, Database.ErrorMessage, "MotelPlus",JOptionPane.ERROR_MESSAGE);
            return;
        }

        //Login
        frmLogin login = new frmLogin(new JFrame(), true,"Real Informática","Motel Plus", "0.1");
        login.setVisible(true);
        if( login.isTrusted)
        {
            launch(MotelPlusApp.class, args);
        }

    }
}
